package com.java1234.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.java1234.entity.*;
import com.java1234.service.UsersService;
import com.java1234.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
* <p>
* 用户表 前端控制器
* </p>
*
* @author Administrator
* @since 2025-05-09
*/
@Controller
@RequestMapping("/sys/users")
public class UsersController {

    @Autowired
    private UsersService service;

    /**
     * 根据条件分页查询用户信息
     * @param pageBean
     * @return
     */
    @PostMapping("/list")
    public R list(@RequestBody PageBean pageBean){
        String query=pageBean.getQuery().trim();
        Page<UsersEntity> pageResult = service
                .page(new Page<>(pageBean.getPageNum(), pageBean.getPageSize())
                ,new QueryWrapper<UsersEntity>().like(StringUtil.isNotEmpty(query)
                        ,"username",query));
        List<UsersEntity> userList = pageResult.getRecords();
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("userList",userList);
        resultMap.put("total",pageResult.getTotal());
        return R.ok(resultMap);
    }

}
